package fractal;

import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: ilya
 * Date: 25.09.11
 * Time: 11:51
 */
public class FancyPalette implements Palette {
    private Color[] palette;

    public FancyPalette() {
        palette = new Color[1000];

        for (int i = 0; i < palette.length; i++) {
            int h = i / 10;
            int s = i % 10;
            palette[i] = new Color(Color.HSBtoRGB(h / 100f, s / 20f + 0.5f, 1f));
        }

        /*double s = 0.95;
        double v = 0.95;
        for (int h = 0; h < 360; h++) {
            double c = v * s;
            double hp = h / 60.0;
            double x = c * (1 - Math.abs(hp % 2 - 1));

            double r1, g1, b1;

            if (hp < 1) {
                r1 = c; g1 = x; b1 = 0;
            } else if (hp < 2) {
                r1 = x; g1 = c; b1 = 0;
            } else if (hp < 3) {
                r1 = 0; g1 = c; b1 = x;
            } else if (hp < 4) {
                r1 = 0; g1 = x; b1 = c;
            } else if (hp < 5) {
                r1 = x; g1 = 0; b1 = c;
            } else *//*if (hp < 6)*//* {
                r1 = c; g1 = 0; b1 = x;
            }
            //v - c, x + v - c, v
            //v - v * s, x + v - v * c, v

            double m = v - c;
            double r = r1 + m;
            double g = g1 + m;
            double b = b1 + m;

            palette[h] = new Color((int) (r * 256), (int) (g * 256), (int) (b * 256));
        }*/
    }

    public Color getColor(int value) {
        return palette[Math.abs(value) % 360];

//        value = (value + 64 + 128) % 256;
//        int v1 = value % 256;
//
//        return new Color(Color.HSBtoRGB(v1 / 256f, 0.6f, 1.0f));
    }
}
